package cn.ml.mybatisdemo;

import cn.ml.mybatisdemo.dao.FenDao;
import cn.ml.mybatisdemo.entity.Fen;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class TestFen {
    public static void main(String[] args) throws IOException {

        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis.cfg.xml"));
        SqlSession sqlSession = sqlSessionFactory.openSession();
        FenDao fenDao = sqlSession.getMapper(FenDao.class);
        System.out.println(fenDao.get(2));
        System.out.println("**************************");
        List<Fen> fens = fenDao.list();
        for (Fen f:fens){
            System.out.println(f);
        }
    }
}
